﻿using System;
using System.Collections.Generic;
using System.Drawing.Design;
using System.Linq;
using System.Text;
using System.ComponentModel;
using System.Xml.Serialization;
using Microsoft.Practices.Modeling.ExtensionProvider.Metadata;
using Microsoft.Practices.Services.ItineraryDsl;
using Microsoft.Practices.Modeling.ExtensionProvider.Extension;
using Microsoft.Practices.Modeling.Common;
using Microsoft.Practices.Modeling.Common.Security;
using Microsoft.Practices.Modeling.Common.Design;
using Microsoft.Practices.Modeling.Services.Design;
using Microsoft.Practices.Modeling.Validation;
using Microsoft.Practices.EnterpriseLibrary.Validation.Validators;
using BizTalk.ESB.Extensions.Helpers;

namespace BizTalk.ESB.Extensions.ResolverExtenders
{
    [Serializable]
    [ObjectExtender(typeof(Resolver))]
    public class StaticValidationResolverExtender : ObjectExtender<Resolver>
    {
        [Category(StaticContextResolverExtenderProvider.ExtensionProviderPropertyCategory),
            Description("Fully qualified XML document type used for validation."),
            DisplayName("Document Type"),
            ReadOnly(false), Browsable(true)]
        [XmlElement]
        public string DocumentType { get; set; }

        [EditorOutputProperty("PolicyVersion", "PolicyVersion", new String[] { }),
            Category(StaticContextResolverExtenderProvider.ExtensionProviderPropertyCategory),
            Description("Specifies the BRE policy containing validation rules"),
            DisplayName("Validation Policy"),
            ReadOnly(false),
            Browsable(true),
            Editor(typeof(BiztalkPolicyEditor), typeof(UITypeEditor)),
            TypeConverter(typeof(TypeConverter))]
        public String PolicyName { get; set; }

        [ReadOnly(false),
            DisplayName("Policy Version"),
            Category("Extender Settings"),
            Description("Specifies the policy version"),
            Browsable(true)]
        public VersionNumber PolicyVersion { get; set; }

        [Category(StaticContextResolverExtenderProvider.ExtensionProviderPropertyCategory),
            Description("Full path to file used for BRE trace information."),
            DisplayName("BRE Trace Path"),
            ReadOnly(false), Browsable(true)]
        [XmlElement]
        public string BreTracePath { get; set; }

        [Category(StaticContextResolverExtenderProvider.ExtensionProviderPropertyCategory),
            Description("Determines if itinerary processing should stop if the message fails validation."),
            DisplayName("Stop On Error"),
            ReadOnly(false),
            Browsable(true)]
        [XmlElement]
        public bool StopOnError { get; set; }

        [Category(StaticContextResolverExtenderProvider.ExtensionProviderPropertyCategory),
            Description("Determines if message validation is executed or skipped."),
            DisplayName("Enabled"),
            ReadOnly(false),
            Browsable(true)]
        [XmlElement]
        public bool Enabled { get; set; }

        [Category(StaticContextResolverExtenderProvider.ExtensionProviderPropertyCategory),
            Description("Determines validation results are published to a one-way or two-way endpoint."),
            DisplayName("Is Request-Response"),
            ReadOnly(false),
            Browsable(true)]
        [XmlElement]
        public bool IsRequestResponse { get; set; }

        [Category(StaticContextResolverExtenderProvider.ExtensionProviderPropertyCategory),
            Description("Value to use for the WCF Action context property."),
            DisplayName("WCF Action"),
            ReadOnly(false), Browsable(true)]
        [XmlElement]
        public string ServiceAction { get; set; }

        [Category(StaticContextResolverExtenderProvider.ExtensionProviderPropertyCategory),
            Description("Value to use for the Itinerary Service Name context property. Is promoted for routing purposes."),
            DisplayName("Service Name"),
            ReadOnly(false), Browsable(true)]
        [XmlElement]
        public string ServiceName { get; set; }

        [Category(StaticContextResolverExtenderProvider.ExtensionProviderPropertyCategory),
            Description("Value to use for the Itinerary Service Type context property. Is promoted for routing purposes."),
            DisplayName("Service Type"),
            ReadOnly(false), Browsable(true)]
        [XmlElement]
        public ServiceType ServiceType { get; set; }
    }

    [Serializable]
    [ObjectExtender(typeof(Resolver))]
    public class BreValidationResolverExtender : ObjectExtender<Resolver>
    {
        [EditorOutputProperty("Version", "Version", new String[] { }),
            Category("Extender Settings"),
            Description("Specifies the policy"),
            DisplayName("Policy"),
            ReadOnly(false),
            Browsable(true),
            Editor(typeof(BiztalkPolicyEditor), typeof(UITypeEditor)),
            TypeConverter(typeof(TypeConverter))]
        public String Policy { get; set; }

        [ReadOnly(false),
            DisplayName("Version"),
            Category("Extender Settings"),
            Description("Specifies the policy version"),
            Browsable(true)]
        public VersionNumber Version { get; set; }

        [Description("Used to recognize the Document Type.  Note: This is a messaging only scenario and is not suppored for Orchestration. i.e. - in case of orchestration, the field will always be set to 'false'."),
            DisplayName("Recognize Message Format"),
            Browsable(true),
            ReadOnly(false),
            Category("Extender Settings")]
        public Boolean RecognizeMessageFormat { get; set; }

        [Description("Determines if the message will be sent to the policy as a fact."),
            ReadOnly(false),
            Browsable(true),
            Category("Extender Settings"),
            DisplayName("UseMsg")]
        public Boolean UseMsg { get; set; }

        [Description("Determines if the message context will be sent to the policy as a fact."),
            ReadOnly(false),
            Browsable(true),
            Category("Extender Settings"),
            DisplayName("UseMsgContext")]
        public Boolean UseMsgContext { get; set; }
    }
}
